<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
    <title>抖查查线上测试平台</title>
</head>
<body>
<div class="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom shadow-sm">
    <a class="btn btn-outline-primary" href="{% url 'Test_interface_automation' %}">返回</a>
</div>
<div class="pricing-header px-3 py-3 pt-md-5 pb-md-4 mx-auto text-center">
    <h1 class="display-10"></h1>
    <form method="post">
        <div class="csrfmiddlewaretoken">{% csrf_token %}</div>
        <h1>弹窗提示token失效后请使用“获取token”获取新的token</h1>
        <div class="container">
            <div class="row justify-content-start">
                <div class="col">
                    <div class="form-group" style="width: 200px;height: 38px">
                        <input type="text" class="form-control Item" placeholder="账号" id="account_number">
                    </div>
                </div>
                <div class="col">
                    <div class="form-group" style="width: 200px;height: 38px">
                        <input type="text" class="form-control Item" placeholder="密码" id="password">
                    </div>
                </div>
                <div class="col-1">
                    <div class="form-group" style="width: 120px;height: 38px;">
                        <button data-casetest=1 type="button" class="btn btn-info test0" onclick="token_pash()">
                            获取token
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <div class="alert-info">
        <p class="lead"><b>New Case</b></p>
    </div>
    <div>
    </div>
</div>
{#{{ Render_details_list }}#}
{% if Render_details_list %}
    <div class="container">
        <form method="post">
            <div class="csrfmiddlewaretoken">{% csrf_token %}</div>
            <div class="row justify-content-start">
                <div class="col">
                    <div class="form-group">
                        <input type="text" class="form-control Item" value="{{ Render_details_list.id }}" id="id"
                               onFocus="if(value==defaultValue){value='{{ Render_details_list.id }}';this.style.color='#000'}">
                    </div>
                </div>
                <div class="col">
                    <div class="form-group">
                        <input type="text" class="form-control Item" value="{{ Render_details_list.entry_name }}"
                               id="entry_name"
                               onFocus="if(value==defaultValue){value='{{ Render_details_list.entry_name }}';this.style.color='#000'}">
                    </div>
                </div>
                <div class="col">
                    <div class="form-group">
                        <input type="text" class="form-control Item" value="{{ Render_details_list.Iterative_version }}"
                               id="Iterative_version"
                               onFocus="if(value==defaultValue){value='{{ Render_details_list.Iterative_version }}';this.style.color='#000'}">
                    </div>
                </div>
                <div class="col">
                    <input type="text" class="form-control Item" value="{{ Render_details_list.modular }}" id="modular"
                           onFocus="if(value==defaultValue){value='{{ Render_details_list.modular }}';this.style.color='#000'}">
                </div>
                <div class="col">
                    <input type="text" class="form-control Item" value="{{ Render_details_list.case_name }}"
                           id="case_name"
                           onFocus="if(value==defaultValue){value='{{ Render_details_list.case_name }}';this.style.color='#000'}">
                </div>
            </div>

            <div id="request" data-index=1>
                <div class="row justify-content-start">
                    <div class="col-2">
                        <div class="form-group">
                            <input type="text" class="form-control Item" value="{{ Render_details_list.User_id }}"
                                   id="User_id"
                                   value="{{ Render_details_list.User_id }}"
                                   onFocus="if(value==defaultValue){value='{{ Render_details_list.User_id }}';this.style.color='#000'}">
                        </div>
                    </div>
                    <div class="col-6">
                        <div class="form-group">
                            <input type="text" class="form-control Item" value="{{ Render_details_list.url }}" id="url"
                                   onFocus="if(value==defaultValue){value='{{ Render_details_list.url }}';this.style.color='#000'}">
                        </div>
                    </div>
                    <div class="col-1">
                        <div class="form-group">
                            <input type="text" class="form-control Item" value="{{ Render_details_list.Token }}"
                                   id="Token"
                                   onFocus="if(value==defaultValue){value='{{ Render_details_list.Token }}';this.style.color='#000'}">
                        </div>
                    </div>
                    <div class="col-3">
                        <div class="form-group">
                            <input type="text" class="form-control Item" value="{{ Render_details_list.Request_type }}"
                                   id="Request_type"
                                   onFocus="if(value==defaultValue){value='{{ Render_details_list.Request_type }}';this.style.color='#000'}">
                        </div>
                    </div>
                </div>
                <div class="row justify-content-start">
                    <div class="col-4">
                        <div class="form-group alert-warning">
                            <p>body请上传json格式</p>
                        </div>
                    </div>
                    <div class="col-4" style="margin-left: 195px">
                        <div class="form-group alert-warning">
                            <p>headers请上传json格式</p>
                        </div>
                    </div>
                </div>
                <div class="row justify-content-start">
                    <div class="col-4" style="margin-left: 185px">
                        <div class="form-group" style="margin-left: -185px">
                            <textarea class="form-control Casebody0" rows="10"
                                      id="Body">{{ Render_details_list.Body }}</textarea>
                        </div>
                    </div>
                    <div class="col-4" style="margin-left: 195px">
                        <div class="form-group" style="margin-left: -185px">
                        <textarea class="form-control Caseheaders0" id="Headers"
                                  rows="10">{{ Render_details_list.Headers }}</textarea>
                        </div>
                    </div>
                </div>
                {#                <div class="row justify-content-start">#}
                {#                    <div class="col-6">#}
                {#                        <div class="form-group">#}
                {#                            <input type="text" class="form-control Item" placeholder="透传参数"#}
                {#                                   value="{{ Render_details_list.Transmission_parameters }}"#}
                {#                                   id="Transmission_parameters"#}
                {#                                   onFocus="if(value==defaultValue){value='{{ Render_details_list.Transmission_parameters }}';this.style.color='#000'}">#}
                {#                        </div>#}
                {#                    </div>#}
                {#                    <div class="col-6">#}
                {#                        <div class="form-group">#}
                {#                            <input type="text" class="form-control Item" placeholder="检查key"#}
                {#                                   value="{{ Render_details_list.Calibration_parameters }}" id="Calibration_parameters"#}
                {#                                   onFocus="if(value==defaultValue){value='{{ Render_details_list.Calibration_parameters }}';this.style.color='#000'}">#}
                {#                        </div>#}
                {#                    </div>#}
                {#                </div>#}
                {#                <div class="row justify-content-start">#}
                {#                    <div class="col-12">#}
                {#                        <div class="form-group">#}
                {#                            <input type="text" class="form-control Item"#}
                {#                                   value="{{ Render_details_list.Replace_parameter }}" placeholder="替换参数"#}
                {#                                   id="Replace_parameter"#}
                {#                                   onFocus="if(value==defaultValue){value='{{ Render_details_list.Replace_parameter }}';this.style.color='#000'}">#}
                {#                        </div>#}
                {#                    </div>#}
                {#                </div>#}
                <div class="row justify-content-start">
                    <div class="col-12">
                        <div class="form-group">
                            <input type="text" class="form-control Item" value="{{ Render_details_list.not_in_null }}"
                                   placeholder="判断不能为空" id="not_in_null"
                                   onFocus="if(value==defaultValue){value='{{ Render_details_list.not_in_null }}';this.style.color='#000'}">
                        </div>
                    </div>
                </div>
                <div class="row justify-content-start">
                    <div class="col-6">
                        <div class="form-group">
                            <textarea class="form-control Response0" rows="0"
                                      placeholder="返回值" id="Return"></textarea>
                        </div>
                    </div>
                    <div class="col-5">
                        <div class="form-group">
                            <textarea class="form-control result0" rows="0" placeholder="测试结果"
                                      id="test_result"></textarea>
                        </div>
                    </div>
                    <div class="col-1">
                        <div class="form-group">
                            <button data-casetest=1 type="button" class="btn btn-info test0"
                                    onclick="casetest()">
                                测试验证
                            </button>
                        </div>
                    </div>
                </div>
                <div class="row justify-content-start">
                    <div class="col-2">
                        <div class="form-group">
                            <button type="button" class="btn btn-danger" onclick="casesave('0')">更新case
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
{% else %}
    <form action="/polls/preservation_interface/" method="post">
        <div class="csrfmiddlewaretoken">{% csrf_token %}</div>
        <div class="container">
            <div class="row justify-content-start">
                <div class="col">
                    <div class="form-group">
                        <input type="text" class="form-control Item" placeholder="列表ID" id="id">
                    </div>
                </div>
                <div class="col">
                    <div class="form-group">
                        <input type="text" class="form-control Item" placeholder="项目名称" id="entry_name">
                    </div>
                </div>
                <div class="col">
                    <div class="form-group">
                        <input type="text" class="form-control Release" placeholder="迭代版本" id="Iterative_version">
                    </div>
                </div>
                <div class="col">
                    <input type="text" class="form-control Modules" placeholder="模块" id="modular">
                </div>
                <div class="col">
                    <input type="text" class="form-control Casename" placeholder="case" id="case_name">
                </div>
            </div>
            <div id="request" data-index=1>
                <div class="row justify-content-start">
                    <div class="col-2">
                        <div class="form-group">
                            <input type="text" class="form-control Caseuid0" placeholder="UID" id="User_id">
                        </div>
                    </div>
                    <div class="col-6">
                        <div class="form-group">
                            <input type="text" class="form-control Caseurl0" placeholder="URL" id="url">
                        </div>
                    </div>
                    <div class="col-1">
                        <div class="form-group">
                            <input type="text" class="form-control" placeholder="token" id="Token">
                        </div>
                    </div>
                    <div class="col-3">
                        <div class="form-group">
                            <input type="text" class="form-control" placeholder="请求类型" id="Request_type">
                        </div>
                    </div>
                </div>
                <div class="row justify-content-start">
                    <div class="col-4">
                        <div class="form-group alert-warning">
                            <p>body请上传json格式</p>
                        </div>
                    </div>
                    <div class="col-4" style="margin-left: 195px">
                        <div class="form-group alert-warning">
                            <p>headers请上传json格式</p>
                        </div>
                    </div>

                </div>
                <div class="row justify-content-start">
                    <div class="col-4" style="margin-left: 185px">
                        <div class="form-group" style="margin-left: -185px">
                            <textarea class="form-control Casebody0" rows="10" placeholder="body" id="Body"></textarea>
                        </div>
                    </div>
                    <div class="col-4" style="margin-left: 195px">
                        <div class="form-group" style="margin-left: -185px">
                        <textarea class="form-control Caseheaders0" rows="10" placeholder="headers"
                                  id="Headers"></textarea>
                        </div>
                    </div>
                </div>
                {#                <div class="row justify-content-start">#}
                {#                    <div class="col-6">#}
                {#                        <div class="form-group">#}
                {#                            <input type="text" class="form-control Casedeliver0" placeholder="透传参数"#}
                {#                                   id="Transmission_parameters">#}
                {#                        </div>#}
                {#                    </div>#}
                {#                    <div class="col-6">#}
                {#                        <div class="form-group">#}
                {#                            <input type="text" class="form-control Casekey0" placeholder="检查key"#}
                {#                                   id="Calibration_parameters">#}
                {#                        </div>#}
                {#                    </div>#}
                {#                </div>#}
                {#                <div class="row justify-content-start">#}
                {#                    <div class="col-12">#}
                {#                        <div class="form-group">#}
                {#                            <input type="text" class="form-control replace0" placeholder="替换参数" id="Replace_parameter">#}
                {#                        </div>#}
                {#                    </div>#}
                {#                </div>#}
                <div class="row justify-content-start">
                    <div class="col-12">
                        <div class="form-group">
                            <input type="text" class="form-control onnull0" placeholder="判断不能为空" id="not_in_null">
                        </div>
                    </div>
                </div>
                <div class="row justify-content-start">
                    <div class="col-6">
                        <div class="form-group">
                            <textarea class="form-control Response0" rows="0"
                                      placeholder="返回值" id="Return"></textarea>
                        </div>
                    </div>
                    <div class="col-5">
                        <div class="form-group">
                            <textarea class="form-control result0" rows="0" placeholder="测试结果"
                                      id="test_result"></textarea>
                        </div>
                    </div>
                    <div class="col-1">
                        <div class="form-group">
                            <button data-casetest=1 type="button" class="btn btn-info test0" onclick="casetest()">
                                测试验证
                            </button>
                        </div>
                    </div>
                </div>
                <div class="row justify-content-start">
                    <div class="col">
                        <div class="col-20 form-group" style="border-bottom: 1px solid #000000"></div>
                    </div>
                </div>
            </div>
            <div class="row justify-content-start">
                <div class="col-2">
                    <div class="form-group">
                        <button type="button" class="btn btn-danger" onclick="casesave()">保存case</button>
                    </div>
                </div>
            </div>
        </div>
    </form>
{% endif %}
<script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://cdn.bootcss.com/popper.js/1.15.0/umd/popper.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script src="https://api.douchacha.com/api/s.js"></script>
<script>
    var x = 0;

    function appendrequest() {
        x = x + 1;
        var caseadd = '<div id="request" data-index=' + x + '><div class="row justify-content-start"><div class="col-2"><div class="form-group"><input type="text" class="form-control Caseuid' + x + '" placeholder="UID" ></div></div><div class="col-7"><div class="form-group"><input type="text" class="form-control Caseurl' + x + '" placeholder="URL"></div></div><div class="col-3"><div class="form-group"><select  class="form-control Caserequest' + x + '"><option>GET</option><option>POST</option></select></div></div></div><div class="row justify-content-start"><div class="col-4" style="margin-left: 185px"><div class="form-group alert-warning"><p>body请上传json格式</p></div></div><div class="col-4" style="margin-left: 195px"><div class="form-group alert-warning"><p>headers请上传json格式</p></div></div></div><div class="row justify-content-start"><div class="col-4"><div class="form-group"><textarea class="form-control Casebody' + x + '" rows="10" placeholder="body"></textarea></div></div><div class="col-4"><div class="form-group"><textarea class="form-control Caseheaders' + x + '" rows="10" placeholder="headers"></textarea></div></div></div><div class="row justify-content-start"><div class="col-6"><div class="form-group"><input  type="text" class="form-control Casedeliver' + x + '" placeholder="透传参数"></div></div><div class="col-6"><div class="form-group"><input type="text" class="form-control Casekey' + x + '" placeholder="检查key"></div></div></div><div class="row justify-content-start"><div class="col-12"><div class="form-group"><input  type="text" class="form-control replace' + x + '" placeholder="替换参数"></div></div></div><div class="row justify-content-start"><div class="col-12"><div class="form-group"><input   type="text" class="form-control onnull' + x + '" placeholder="不为空检查"></div></div></div><div class="row justify-content-start"><div class="col-6"><div class="form-group"><textarea class="form-control Response' + x + '" rows="10" placeholder="返回值"></textarea></div></div><div class="col-5"><div class="form-group"><textarea class="form-control result' + x + '" rows="10" placeholder="测试结果"></textarea></div></div><div class="col-1"><div class="form-group"><button data-casetest=' + x + '  type="button" class="btn btn-info test' + x + '" onclick="casetest(' + x + ')">测试验证</button></div></div></div><div class="row justify-content-start"><div class="col"><div class="col-20 form-group"  style="border-bottom: 1px solid #000000"></div></div></div></div>'
        $('#request').append(caseadd);        // 追加新元素
    }

    function casesave(update_id) {
        $.ajaxSetup({
            data: {csrfmiddlewaretoken: '{{ csrf_token }}'}
        })
        if (update_id) {
            var id = document.getElementById('id') && document.getElementById('id').value
            var entry_name = document.getElementById('entry_name') && document.getElementById('entry_name').value
            var Iterative_version = document.getElementById('Iterative_version') && document.getElementById('Iterative_version').value
            var modular = document.getElementById('modular') && document.getElementById('modular').value
            var case_name = document.getElementById('case_name') && document.getElementById('case_name').value
            var User_id = document.getElementById('User_id') && document.getElementById('User_id').value
            var url = document.getElementById('url') && document.getElementById('url').value
            var Token = document.getElementById('Token') && document.getElementById('Token').value
            var Request_type = document.getElementById('Request_type') && document.getElementById('Request_type').value
            var Body = document.getElementById('Body') && document.getElementById('Body').value
            var Headers = document.getElementById('Headers') && document.getElementById('Headers').value
            {#var Transmission_parameters = document.getElementById('Transmission_parameters') && document.getElementById('Transmission_parameters').value#}
            {#var Calibration_parameters = document.getElementById('Calibration_parameters') && document.getElementById('Calibration_parameters').value#}
            {#var Replace_parameter = document.getElementById('Replace_parameter') && document.getElementById('Replace_parameter').value#}
            var not_in_null = document.getElementById('not_in_null') && document.getElementById('not_in_null').value
            $.ajax(
                {
                    type: "POST",
                    url: "http://127.0.0.1:8089/polls/preservation_interface",
                    data: {
                        updata: 111,
                        id: id,
                        entry_name: entry_name,
                        Iterative_version: Iterative_version,
                        modular: modular,
                        case_name: case_name,
                        User_id: User_id,
                        url: url,
                        Token: Token,
                        Request_type: Request_type,
                        Body: Body,
                        Headers: Headers,
                        {#Transmission_parameters: Transmission_parameters,#}
                        {#Calibration_parameters: Calibration_parameters,#}
                        {#Replace_parameter: Replace_parameter,#}
                        not_in_null: not_in_null
                    },
                    success: function (data) {
                        alert(data)
                    }

                })
        } else {
            var id_1 = document.getElementById('id') && document.getElementById('id').value
            var entry_name_1 = document.getElementById('entry_name') && document.getElementById('entry_name').value
            var Iterative_version_1 = document.getElementById('Iterative_version') && document.getElementById('Iterative_version').value
            var modular_1 = document.getElementById('modular') && document.getElementById('modular').value
            var case_name_1 = document.getElementById('case_name') && document.getElementById('case_name').value
            var User_id_1 = document.getElementById('User_id') && document.getElementById('User_id').value
            var url_1 = document.getElementById('url') && document.getElementById('url').value
            var Token_1 = document.getElementById('Token') && document.getElementById('Token').value
            var Request_type_1 = document.getElementById('Request_type') && document.getElementById('Request_type').value
            var Body_1 = document.getElementById('Body') && document.getElementById('Body').value
            var Headers_1 = document.getElementById('Headers') && document.getElementById('Headers').value
            {#var Transmission_parameters_1 = document.getElementById('Transmission_parameters') && document.getElementById('Transmission_parameters').value#}
            {#var Calibration_parameters_1 = document.getElementById('Calibration_parameters') && document.getElementById('Calibration_parameters').value#}
            {#var Replace_parameter_1 = document.getElementById('Replace_parameter') && document.getElementById('Replace_parameter').value#}
            var not_in_null_1 = document.getElementById('not_in_null') && document.getElementById('not_in_null').value
            $.ajax(
                {
                    type: "POST",
                    url: "http://127.0.0.1:8089/polls/preservation_interface",
                    data: {
                        id: id_1,
                        entry_name: entry_name_1,
                        Iterative_version: Iterative_version_1,
                        modular: modular_1,
                        case_name: case_name_1,
                        User_id: User_id_1,
                        url: url_1,
                        Token: Token_1,
                        Request_type: Request_type_1,
                        Body: Body_1,
                        Headers: Headers_1,
                        {#Transmission_parameters: Transmission_parameters_1,#}
                        {#Calibration_parameters: Calibration_parameters_1,#}
                        {#Replace_parameter: Replace_parameter_1,#}
                        not_in_null: not_in_null_1
                    },
                    success: function (data) {
                        console.log(111)
                        alert(data)
                    }

                })
        }
    }

    function casetest() {
        $.ajaxSetup({
            data: {csrfmiddlewaretoken: '{{ csrf_token }}'}
        })
        var User_id_1 = document.getElementById('User_id') && document.getElementById('User_id').value
        var url_1 = document.getElementById('url') && document.getElementById('url').value
        var Token_1 = document.getElementById('Token') && document.getElementById('Token').value
        var Request_type_1 = document.getElementById('Request_type') && document.getElementById('Request_type').value
        var Body_1 = document.getElementById('Body') && document.getElementById('Body').value
        var Headers_1 = document.getElementById('Headers') && document.getElementById('Headers').value
        {#var Transmission_parameters_1 = document.getElementById('Transmission_parameters') && document.getElementById('Transmission_parameters').value#}
        {#var Calibration_parameters_1 = document.getElementById('Calibration_parameters') && document.getElementById('Calibration_parameters').value#}
        {#var Replace_parameter_1 = document.getElementById('Replace_parameter') && document.getElementById('Replace_parameter').value#}
        var not_in_null_1 = document.getElementById('not_in_null') && document.getElementById('not_in_null').value
        $.ajax(
            {
                type: "POST",
                url: "http://127.0.0.1:8089/polls/Test_verification",
                data: {
                    User_id: User_id_1,
                    url: url_1,
                    Token: Token_1,
                    Request_type: Request_type_1,
                    Body: Body_1,
                    Headers: Headers_1,
                    {#Transmission_parameters: Transmission_parameters_1,#}
                    {#Calibration_parameters: Calibration_parameters_1,#}
                    {#Replace_parameter: Replace_parameter_1,#}
                    not_in_null: not_in_null_1
                },
                success: function (data) {
                    var Return = document.getElementById('Return')
                    var test_result = document.getElementById('test_result')
                    Return.value = data
                    if (Return.value = data) {
                        test_result.value = '老铁,莫有毛病这个接口正常!'
                    }
                }
            })
    }


    function token_pash() {
        var account_number = document.getElementById('account_number') && document.getElementById('account_number').value
        var password = document.getElementById('password') && document.getElementById('password').value
        $.ajaxSetup({
            data: {csrfmiddlewaretoken: '{{ csrf_token }}'}
        })
        $.ajax(
            {
                type: "POST",
                url: "http://127.0.0.1:8089/polls/get_token",
                data: {
                    account_number: account_number,
                    password: password,
                },
                success: function (data) {
                    if (data == 300) {
                        alert('账号或者密码填写错误！')
                        window.location.reload()
                    } else {
                        copy(data)
                        window.location.reload()
                    }
                }
            })

    }

    function copy(share) {
        var _input = document.createElement('input')
        _input.value = share
        document.body.appendChild(_input)
        _input.select()
        document.execCommand('Copy')
        document.body.removeChild(_input)
        alert("链接复制成功啦，快去分享给好友吧")
    }
</script>
</body>
</html>